import uuid
from datetime import datetime

from django.db import models


# Create your models here.
# 1:省份(name)
def get_upload_path(instance, filename):
    print(instance)
    print(filename)
    ext = filename.split('.')[-1]
    print(ext)
    filename = f'{uuid.uuid4()}.{ext}'
    now = datetime.now()
    return f'student/{now.year}/{now.month}/{now.day}/{filename}'


class Province(models.Model):
    name = models.CharField(max_length=20, verbose_name='景区代表')

    class Meta:
        db_table = 'province'
        verbose_name = '省份'
        verbose_name_plural = verbose_name



# 2:直辖市(
class Municipality(models.Model):
    STATUS_END = (
        ('M', '出名'),
        ('F', '不出名'),
)
    name = models.CharField(max_length=20, verbose_name='辖区名称')
    longitude = models.CharField(max_length=20, verbose_name='经度')
    img = models.ImageField(upload_to=get_upload_path, verbose_name='标志性图片')
    food = models.CharField(max_length=20, verbose_name='食物')
    status = models.CharField(max_length=20, choices=STATUS_END, default='F', verbose_name='是否出名')
    create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    province = models.ForeignKey(Province, on_delete=models.CASCADE, verbose_name='景区代表')
    class Meta:
        db_table = 'municipality'
        verbose_name = '直辖市'
        verbose_name_plural = verbose_name


